package com.snail.billing.json;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonQueryState extends JsonBase {

	private List<QueryState> data;

	public JsonQueryState(String jsonString) {
		super(jsonString);
		try {
			if (getCode() == 1) {
				JSONObject json = new JSONObject(jsonString);
				JSONArray jsonArray = json.getJSONArray("data");
				data = new ArrayList<QueryState>();
				for (int i = 0; i < jsonArray.length(); i++) {
					QueryState state = new QueryState(jsonArray.getString(i));
					data.add(state);
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public List<QueryState> getData() {
		return data;
	}

	public class QueryState {
		private int receiveState;
		private String targetNumber;
		private int levels;
		private String mobileName;
		private String mobileCode;
		private int sendState;
		private boolean sendSms;

		public QueryState(String jsonString) {
			try {
				JSONObject json = new JSONObject(jsonString);
				if (json.has("receiveState")) {
					receiveState = json.getInt("receiveState");
				}
				if (json.has("targetNumber")) {
					targetNumber = json.getString("targetNumber");
				}
				if (json.has("levels")) {
					levels = json.getInt("levels");
				}
				if (json.has("mobileName")) {
					mobileName = json.getString("mobileName");
				}
				if (json.has("mobileCode")) {
					mobileCode = json.getString("mobileCode");
				}
				if (json.has("sendState")) {
					sendState = json.getInt("sendState");
				}
				if (json.has("sendSms")) {
					sendSms = json.getBoolean("sendSms");
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		public int getReceiveState() {
			return receiveState;
		}

		public String getTargetNumber() {
			return targetNumber;
		}

		public int getLevels() {
			return levels;
		}

		public String getMobileName() {
			return mobileName;
		}

		public String getMobileCode() {
			return mobileCode;
		}

		public int getSendState() {
			return sendState;
		}

		public boolean isSendSms() {
			return sendSms;
		}
	}
}
